﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Common;
using EcSalseManage.App_Code;
using System.IO;
using System.Net;

namespace EcSalseManage.EcSalse
{
    public partial class Salse_Detail : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                if (!CommonFunction.isInPrev("Project_Deal_0001"))
                {
                    Response.Redirect("../Error/Perm_Error.aspx");
                }
                if (!CommonFunction.isInPrev("Project_Deal_0002"))
                {
                    this.btnSubmit.Enabled = false;
                }
                if (!CommonFunction.isInPrev("Project_Deal_0003"))
                {
                    this.btnDelete.Enabled = false;
                }

                #region 初始化加载数据
                LoadPagedb();

                DataSet ds = new DataSet();

                DataAccess.Operate.DA_Report_Attach_Inherit Report_Attach_Inherit = new DataAccess.Operate.DA_Report_Attach_Inherit();
                ds = Report_Attach_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlFileType, ds.Tables[0], "Report_File_ID", "Report_File_Name", "", "--请选择附件类型--");
                //this.btnUpLoad.Attributes.Add("onclick", "return DataCheck();");

                wsKDHR.Service wsKDHRMS = new wsKDHR.Service();
                DataAccess.Operate.DA_Project_Department_Inherit Project_Department_Inherit = new DataAccess.Operate.DA_Project_Department_Inherit();
                DataAccess.Operate.DA_Project_SignType_Inherit Project_SignType_Inherit = new DataAccess.Operate.DA_Project_SignType_Inherit();
                DataAccess.Operate.DA_Project_Present_Inherit Project_Present_Inherit = new DataAccess.Operate.DA_Project_Present_Inherit();
                DataAccess.Operate.DA_Project_Province_Inherit Project_Province_Inherit = new DataAccess.Operate.DA_Project_Province_Inherit();
                DataAccess.Operate.DA_Project_ProductType_Inherit Project_ProductType_Inherit = new DataAccess.Operate.DA_Project_ProductType_Inherit();
                DataAccess.Operate.DA_Project_AgencyType_Inherit Project_AgencyType_Inherit = new DataAccess.Operate.DA_Project_AgencyType_Inherit();
                DataAccess.Operate.DA_Project_Encourage_Inherit Project_Encourage1_Inherit = new DataAccess.Operate.DA_Project_Encourage_Inherit();
                DataAccess.Operate.DA_Project_Lease1_Inherit Project_Lease1_Inherit = new DataAccess.Operate.DA_Project_Lease1_Inherit();
                DataAccess.Operate.DA_Project_AccountCycle_Inherit Project_AccountCycle_Inherit = new DataAccess.Operate.DA_Project_AccountCycle_Inherit();
                DataAccess.Operate.DA_Project_AccountCondition_Inherit Project_AccountCondition_Inherit = new DataAccess.Operate.DA_Project_AccountCondition_Inherit();
                DataAccess.Operate.DA_Project_BidderAccountCondition_Inherit Project_BidderAccountCondition_Inherit = new DataAccess.Operate.DA_Project_BidderAccountCondition_Inherit();
                DataAccess.Operate.DA_Project_SalseAccountCondition_Inherit Project_SalseAccountCondition_Inherit = new DataAccess.Operate.DA_Project_SalseAccountCondition_Inherit();
                DataAccess.Operate.DA_Project_Referral_Inherit Project_Referral_Inherit = new DataAccess.Operate.DA_Project_Referral_Inherit();


                this.ddlDeveloperProvince.Attributes.Add("onchange", "FillCity(this,document.form1.ddlDeveloperCity);");
                this.ddlDeveloperCity.Attributes.Add("onchange", "FillDistrict(this,document.form1.ddlDeveloperDistrict);");
                this.ddlDeveloperDistrict.Attributes.Add("onchange", "FillDistrictType(this,document.form1.ddlDistrictType);");
                this.ddlQqch2.Attributes.Add("onchange", "javascript: if(document.all.ddlQqch2.selectedIndex == 0){ var a = window.prompt('请输入多少天', '0');document.getElementById('txtQqch21').value = a;document.all.ddlQqch2.options[document.all.ddlQqch2.selectedIndex].text = '每月' + a + '日';}");
                this.ddlXsdl.Attributes.Add("onchange", "javascript: if(document.all.ddlXsdl.selectedIndex == 0){ var a = window.prompt('请输入多少%', '0');document.getElementById('hfldXsdlB2').value = a;document.all.ddlXsdl.options[document.all.ddlXsdl.selectedIndex].text = '按成交金额的' + a + '%计提';}else if(document.all.ddlXsdl.selectedIndex == 1){var a = window.prompt('请输入多少元', '0');document.getElementById('hfldXsdlB2').value = a;document.all.ddlXsdl.options[document.all.ddlXsdl.selectedIndex].text = '每套按' + a + '元收取手续费';}");
                this.ddlZz.Attributes.Add("onchange", "javascript: if(document.all.ddlZz.selectedIndex == 0){ var a = window.prompt('请输入多少%', '0');document.getElementById('hfldZzB2').value = a;document.all.ddlZz.options[document.all.ddlZz.selectedIndex].text = '按成交金额的' + a + '%计提';}else if(document.all.ddlZz.selectedIndex == 1){var a = window.prompt('请输入多少元', '0');document.getElementById('hfldZzB2').value = a;document.all.ddlZz.options[document.all.ddlZz.selectedIndex].text = '每套按' + a + '元收取手续费';}");
                this.ddlPoint.Attributes.Add("onchange", "javascript: if(document.all.ddlPoint.selectedIndex == 1){ var a = window.prompt('请输入多少倍', '0');document.getElementById('hfdlPoint').value = a;document.all.ddlPoint.options[document.all.ddlPoint.selectedIndex].text = '月均租金的' + a + '倍计提';}");
                this.ddlSignType.Attributes.Add("onchange", "ddlSingType();");
                string strJS = "window.open('Project_getEmployeeDetail.aspx?fun=getEmployee','','scrollbars=yes,width=720,height=460,status=yes,resizable=yes');return false;";
                this.ibtnMarketing1.Attributes.Add("onclick", strJS);
                //this.DropDownList1.Attributes.Add("onchange", "showHrKD(this)");
                this.ddlProjectState.Attributes.Add("onchange", "changeProjectState(this)");

                ds = Project_Department_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlDepartment, ds.Tables[0], "Project_Deparement_ID", "Project_Deparement_Name", "", "--请选择所属部门--");

                ds = Project_SignType_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlSignType, ds.Tables[0], "Project_SignType_ID", "Project_SignType_Name", "", "--请选择签署类型--");

                ds = Project_Present_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlProjectState, ds.Tables[0], "Project_Present_ID", "Project_Present_Name", "", "--请选择项目现况--");

                ds = Project_Province_Inherit.FindLibrary();
                Common.Common_Function.DropDownListBind(ddlDeveloperProvince, ds.Tables[0], "Province_ID", "Province_Name", "", "--请选择项目现况--");

                ds = Project_ProductType_Inherit.FindLibraryAll();
                Common.Common_Function.CheckBoxListBind(chklProductType, ds.Tables[0], "Project_ProductType_ID", "Project_ProductType_Name");

                ds = Project_AgencyType_Inherit.FindLibraryAll();
                CheckBoxNew(chklAgencyType, ds.Tables[0]);

                ds = Project_Encourage1_Inherit.FindLibrary();

                Common.Common_Function.RadioButtonListBind(radlEncourage, ds.Tables[0], "Project_Encourage1_ID", "Project_Encourage1_Name", "");
                Common.Common_Function.RadioButtonListBind(radlSalseAgency, ds.Tables[0], "Project_Encourage1_ID", "Project_Encourage1_Name", "");
                Common.Common_Function.RadioButtonListBind(radlUnionComm, ds.Tables[0], "Project_Encourage1_ID", "Project_Encourage1_Name", "");
                Common.Common_Function.RadioButtonListBind(radlUnionDeveloper, ds.Tables[0], "Project_Encourage1_ID", "Project_Encourage1_Name", "");
                radlUnionComm.Attributes.Add("onclick", "document.getElementById('UnionCommArea').innerHTML='';u=1;");
                radlSalseAgency.Attributes.Add("onclick", "document.getElementById('SalseAgencyArea').innerHTML='';s=1;");

                ds = Project_Lease1_Inherit.FindLibrary();
                Common.Common_Function.RadioButtonListBind(radlLease, ds.Tables[0], "Project_Lease1_ID", "Project_Lease1_Name", "");
                radlLease.Attributes.Add("onclick", "document.getElementById('LeaseArea').innerHTML='';l=1;");

                ds = Project_AccountCycle_Inherit.FindLibrary();
                RadioButtonNew(radlAccountCycle, ds.Tables[0]);

                ds = Project_AccountCondition_Inherit.FindLibrary();
                CheckBoxNew(chklAccountCondition, ds.Tables[0]);

                ds = Project_BidderAccountCondition_Inherit.FindLibrary();
                CheckBoxNew(chklBidderAccountCondition, ds.Tables[0]);

                ds = Project_SalseAccountCondition_Inherit.FindLibrary();
                RadioButtonNew(radlSalseAccountCondition, ds.Tables[0]);

                ds = Project_Referral_Inherit.FindLibrary();
                RadioButtonNew(radlOutComm, ds.Tables[0]);
                RadioButtonNew(radlReferral, ds.Tables[0]);

                this.ibtnMarketing1.Attributes.Add("onclick", "window.open('Project_getEmployeeDetail.aspx?fun=getEmployee_Marketing1','','scrollbars=yes,width=720,height=460,status=yes,resizable=yes');return false;");
                this.ibtnMarketing2.Attributes.Add("onclick", "window.open('Project_getEmployeeDetail.aspx?fun=getEmployee_Marketing2','','scrollbars=yes,width=720,height=460,status=yes,resizable=yes');return false;");
                this.ibtnManager.Attributes.Add("onclick", "window.open('Project_getEmployeeDetail.aspx?fun=getEmployee_Manager','','scrollbars=yes,width=720,height=460,status=yes,resizable=yes');return false;");
                this.ibtnBusiness.Attributes.Add("onclick", "window.open('Project_getEmployeeDetail.aspx?fun=getEmployee_Business','','scrollbars=yes,width=720,height=460,status=yes,resizable=yes');return false;");
                this.ibtnDepartmentHead.Attributes.Add("onclick", "window.open('Project_getEmployeeDetail.aspx?fun=getEmployee_DepartmentHead','','scrollbars=yes,width=720,height=460,status=yes,resizable=yes');return false;");

                #endregion

                if (Request.QueryString["ProjectID"] != null)
                {
                    ViewState["ProjectID"] = Request.QueryString["ProjectID"].ToString();
                    lblTitle.Text = "修改项目";
                    Update_Data_Bind(ViewState["ProjectID"].ToString());
                    this.dgList.Visible = true;
                    BindGrid();
                    this.btnDelete.Visible = true;
                    this.Report_Tab1.Visible = true;
                    this.Report_Tab1.ExchangeTypeID = "11";
                    this.Report_Tab1.MainID = ViewState["ProjectID"].ToString();
                    this.btnReset.Visible = false;
                    this.btnUpLoad.Visible = true;
                }
                else
                {
                    lblTitle.Text = "新增项目";
                    ViewState["ProjectID"] = null;
                    this.btnAudit.Visible = false;
                }

            }


        }

        public void CheckBoxNew(CheckBoxList chkl, DataTable tb)
        {
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                ListItem item = new ListItem(tb.Rows[i][1].ToString(), tb.Rows[i][0].ToString());
                item.Attributes.Add("onclick", "chklAgencyType(this);");
                chkl.Items.Add(item);
            }
        }

        public void RadioButtonNew(RadioButtonList rad, DataTable db)
        {

            for (int i = 0; i < db.Rows.Count; i++)
            {
                ListItem item = new ListItem(db.Rows[i][1].ToString(), db.Rows[i][0].ToString());
                item.Attributes.Add("onclick", "chklAgencyType(this);");
                rad.Items.Add(item);
            }
        }


        public void LoadPagedb()
        {
            //发展商客，条款内容A
            ListItem item = new ListItem("____套以内", "1");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            radlXsdl.Items.Add(item);
            item = new ListItem("____套以内", "1");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            radlZz.Items.Add(item);
            item = new ListItem("可售货量____套的____%以内", "2");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            radlXsdl.Items.Add(item);
            item = new ListItem("可售货量____套的____%以内", "2");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            radlZz.Items.Add(item);

            //发展商客，条款内容B
            item = new ListItem("按成交金额的____%计提", "1");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            ddlXsdl.Items.Add(item);
            item = new ListItem("按成交金额的____%计提", "1");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            ddlZz.Items.Add(item);
            item = new ListItem("每套按____元收取手续费", "2");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            ddlXsdl.Items.Add(item);
            item = new ListItem("每套按____元收取手续费", "2");
            item.Attributes.Add("onclick", "chklAgencyType(this);");
            ddlZz.Items.Add(item);


        }

        #region 保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {


            DataEntity.T_Project Project = new DataEntity.T_Project();
            DataAccess.Operate.DA_Project_Operate Project_Operate = new DataAccess.Operate.DA_Project_Operate();
            DataAccess.Operate.DA_Project_Inherit Project_Inherit = new DataAccess.Operate.DA_Project_Inherit();

            Guid gProjectID = System.Guid.NewGuid();

            Project.Project_ID = gProjectID;
            Project.Project_Name = this.txtProjectName.Text.Trim();
            Project.Project_SignDate = Convert.ToDateTime(this.txtSignDate.Text.Trim());
            Project.Project_DepartmentID = Convert.ToInt32(this.ddlDepartment.SelectedValue.ToString());
            Project.Project_SignTypeID = Convert.ToInt32(this.ddlSignType.SelectedValue.ToString());
            Project.Project_AgencyDateBegin = Convert.ToDateTime(this.txtDateStart.Text.Trim());
            Project.Project_AgencyDateEnd = Convert.ToDateTime(this.txtDateEnd.Text.Trim());
            Project.Project_Developer = this.txtDeveloper.Text.Trim();
            Project.Project_DeveloperProvinceID = Convert.ToInt32(this.ddlDeveloperProvince.SelectedValue.ToString());
            Project.Project_DeveloperAddress = this.txtDeveloperAddress.Text.Trim();
            Project.Project_PresentID = Convert.ToInt32(this.ddlProjectState.SelectedValue.ToString());
            Project.Project_AccountCycle = Convert.ToInt32(this.radlAccountCycle.SelectedValue.ToString());            //结算周期
            Project.Project_AccountCycle_FirstA1 = this.hfldAccountCycle.Value;
            Project.Project_AccountCondition = Convert.ToInt32(this.radlSalseAccountCondition.SelectedValue.ToString()); //以完成销售目标为结算条件
            Project.Project_AccountCondition_FirstA1 = this.hfldSalseAccountCondition.Value;
            Project.Project_OutComm_ID = Convert.ToInt32(radlOutComm.SelectedValue);
            Project.Project_OutComm_FirstA1 = this.hfldOutComm1.Value;
            Project.Project_Referral_ID = Convert.ToInt32(radlReferral.SelectedValue);
            Project.Project_Referral_FirstA1 = this.hfldReferral1.Value;
            Project.Project_AvailableArea =Convert.ToDecimal(this.txtProject_AvailableArea.Text.Trim());
            Project.Project_AvailableVolume =Convert.ToDecimal(this.txtProject_AvailableVolume.Text.Trim());
            Project.Project_DirecterCode = this.hfldMarketing1.Value;
            Project.Project_Directer = this.txtMarketing1.Text.Trim();
            Project.Project_Directer1Code = this.hfldMarketing2.Value;
            Project.Project_Directer1 = this.txtMarketing2.Text;
            Project.Project_ManagerCode = this.hfldManager.Value;
            Project.Project_Manager = this.txtManager.Text.Trim();
            Project.Project_Business = this.txtBusiness.Text.Trim();
            Project.Project_BusinessCode = this.hfldBusiness.Value.ToString();
            Project.Project_DepartmentHead = this.txtDepartmentHead.Text.Trim();
            Project.Project_DepartmentHeadCode = this.hfldDepartmentHead.Value.Trim();
           

            if (ViewState["ProjectID"]==null)
            {
                Project.Project_Audit = 1;
                Project.Project_NO = Project_Inherit.genProjectNO();
                Project.ProjectNOIdx = Project_Inherit.genProjectIndex().ToString();
                Project.Project_DeveloperCityID = Convert.ToInt32(Request.Form["ddlDeveloperCity"].ToString());
                Project.Project_DeveloperDistrictID = Convert.ToInt32(Request.Form["ddlDeveloperDistrict"].ToString());
                Project.Project_DeveloperDistrictPropertyID = Convert.ToInt32(Request.Form["ddlDistrictType"].ToString());
                Project_Operate.Insert(Project);

                DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 1, gProjectID, 1);
                
                #region 上传附件部分
                DataAccess.Operate.DA_Report_Attach_Operate Report_Attach_Operate = new DataAccess.Operate.DA_Report_Attach_Operate();
                DataEntity.T_Report_Attach Report_Attach = new DataEntity.T_Report_Attach();
                string sFileName = "";
                string sFilePath = "";
                string sFileType = "";
 
                if (!Directory.Exists("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString()))
                {
                    Directory.CreateDirectory("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString());
                }
                if (!Directory.Exists("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString() + "\\" + gProjectID.ToString()))
                {
                    Directory.CreateDirectory("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString() + "\\" + gProjectID.ToString());
                }

                sFileType = CommonFunction.CheckFileType(this.txtFilePath.PostedFile.FileName);
                if (sFileType != "")
                {
                    sFileName = gProjectID.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + sFileType;
                }

                sFilePath = "/ReportManager/" + DateTime.Now.Year + "/" + gProjectID.ToString() + "/" + sFileName;
                try
                {
                    Report_Attach.Project_Report_FileDesc = this.txtProjectDesc.Text.Trim();
                    Report_Attach.Project_Report_FileName = sFileName;
                    Report_Attach.Project_Report_FilePath = sFilePath;
                    Report_Attach.Project_Report_ExchangeTypeID = 11;
                    Report_Attach.Project_Report_FileID =Convert.ToInt32(this.ddlFileType.SelectedValue);
                    Report_Attach.Project_Report_MainID = gProjectID;
                    Report_Attach_Operate.Insert(Report_Attach);
                    this.txtFilePath.PostedFile.SaveAs("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString() + "\\" + gProjectID.ToString() + "\\" + sFileName);
                    DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 5, gProjectID, 4);
                   
                }
                catch (System.Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
                finally
                {
                 
                }

                #endregion

              

            }
            else
            {
                int cityID = 0;
                int disID = 0;
                int distypeID = 0;
                int.TryParse(this.ddlDeveloperCity.SelectedItem.Value, out cityID);
                Project.Project_DeveloperCityID = cityID;

                int.TryParse(this.ddlDeveloperDistrict.SelectedItem.Value, out disID);
                Project.Project_DeveloperDistrictID = disID;

                int.TryParse(this.ddlDistrictType.SelectedItem.Value, out distypeID);
                Project.Project_DeveloperDistrictPropertyID = distypeID;

                Project.Project_ID = new Guid(ViewState["ProjectID"].ToString());

                Project_Operate.Update(Project);

                DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 1, gProjectID, 2);
            }

            #region 人事树操作部分
            DataAccess.Operate.DA_Project_Hr_Inherit Project_Hr_Inherit = new DataAccess.Operate.DA_Project_Hr_Inherit();
            DataAccess.Operate.DA_Project_Hr_Operate Project_Hr_Operate = new DataAccess.Operate.DA_Project_Hr_Operate();
            if (ViewState["ProjectID"] == null)
                Project_Hr_Inherit.DeleteByMainID(gProjectID.ToString());
            else
                Project_Hr_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
            DataEntity.T_Project_Hr Project_Hr = new DataEntity.T_Project_Hr();
            for (int i = 0; i < lstHr.Items.Count; i++)
            {
                Project_Hr.Project_Hr_KDNameID =new Guid(lstHr.Items[i].Value);
                Project_Hr.Project_Hr_KDName = lstHr.Items[i].Text;
                if (ViewState["ProjectID"] == null)
                    Project_Hr.Project_Hr_MainID = gProjectID;
                else
                    Project_Hr.Project_Hr_MainID = new Guid(ViewState["ProjectID"].ToString());
                Project_Hr_Operate.Insert(Project_Hr);
            }
            #endregion




            //代理类型
            DataEntity.T_Project_AgencyType Project_AgencyType = new DataEntity.T_Project_AgencyType();
            DataAccess.Operate.DA_Project_AgencyType_Operate Project_AgencyType_Operate = new DataAccess.Operate.DA_Project_AgencyType_Operate();
            Project_AgencyType.Project_AgencyType_MainID = gProjectID;
            if (ViewState["ProjectID"] != null)
            {
                Project_AgencyType.Project_AgencyType_MainID = new Guid(ViewState["ProjectID"].ToString());
                DataAccess.Operate.DA_Project_AgencyType_Inherit Project_AgencyType_Inherit = new DataAccess.Operate.DA_Project_AgencyType_Inherit();
                Project_AgencyType_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
            }
            for (int i = 0; i < chklAgencyType.Items.Count; i++)
            {
                if (chklAgencyType.Items[i].Selected)
                {
                    Project_AgencyType.Project_AgencyType_TypeID = Convert.ToInt32(chklAgencyType.Items[i].Value.ToString());
                    Project_AgencyType_Operate.Insert(Project_AgencyType);
                }
            }

            #region 额外奖励部分
            DataEntity.T_Project_Encourage Project_Encourage = new DataEntity.T_Project_Encourage();
            if (this.hfldEncourage.Value != "")
            {
                string[] arrayEncourage = this.hfldEncourage.Value.Substring(0, this.hfldEncourage.Value.Length - 1).Split('|');
                Project_Encourage.Project_Encourage_FirstA1 = Convert.ToInt32(this.radlEncourage.SelectedValue);
                DataAccess.Operate.DA_Project_Encourage_Operate Project_Encourage_Operate = new DataAccess.Operate.DA_Project_Encourage_Operate();
                DataAccess.Operate.DA_Project_Encourage_Inherit Project_Encourage_Inherit = new DataAccess.Operate.DA_Project_Encourage_Inherit();
                if (ViewState["ProjectID"] != null)
                {
                    Project_Encourage.Project_Encourage_MainID =new Guid(ViewState["ProjectID"].ToString());
                    Project_Encourage_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                }
                else
                {
                    Project_Encourage.Project_Encourage_MainID = gProjectID;
                }

                for (int i = 0; i < arrayEncourage.Length; i++)
                {
                    string[] entityitem = arrayEncourage[i].Split(',');
                    Project_Encourage.Project_Encourage_FirstA2 = entityitem[0];
                    Project_Encourage.Project_Encourage_FirstA3 = entityitem[1];
                    Project_Encourage_Operate.Insert(Project_Encourage);
                }
            }
            #endregion

            #region 前期策划部分
            DataEntity.T_Project_EarlyPlot Project_EarlyPlot = new DataEntity.T_Project_EarlyPlot();
            if (chklAgencyType.Items[0].Selected)
            {
                Project_EarlyPlot.Project_EarlyPlot_MainID = gProjectID;
                Project_EarlyPlot.Project_EarlyPlot_Fees =Convert.ToDecimal(txtProject_EarlyPlot_Fees.Text.Trim());
                Project_EarlyPlot.Project_EarlyPlot_FirstA1 = txtQqchA1.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstA2 = Convert.ToInt32(ddlQqchA.SelectedValue.ToString());
                Project_EarlyPlot.Project_EarlyPlot_FirstA3 = txtQqchA2.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstB1 = txtQqchB1.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstB2 = Convert.ToInt32(ddlQqchB.SelectedValue.ToString());
                Project_EarlyPlot.Project_EarlyPlot_FirstB3 = txtQqchB2.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstC1 = txtQqchC1.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstC2 = Convert.ToInt32(ddlQqchC.SelectedValue.ToString());
                Project_EarlyPlot.Project_EarlyPlot_FirstC3 = txtQqchC2.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstD1 = txtQqchD1.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstD2 = Convert.ToInt32(ddlQqchD.SelectedValue.ToString());
                Project_EarlyPlot.Project_EarlyPlot_FirstD3 = txtQqchD2.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstE1 = txtQqchE1.Text.Trim();
                Project_EarlyPlot.Project_EarlyPlot_FirstE2 = Convert.ToInt32(ddlQqchE.SelectedValue.ToString());
                Project_EarlyPlot.Project_EarlyPlot_FirstE3 = txtQqchE2.Text.Trim();

                Project_EarlyPlot.Project_EarlyPlot_Second1 = txtQqch21.Value;
                Project_EarlyPlot.Project_EarlyPlot_Second2 = Convert.ToInt32(ddlQqch2.SelectedValue.ToString());
                Project_EarlyPlot.Project_EarlyPlot_Second3 = txtQqch22.Text.Trim();

                DataAccess.Operate.DA_Project_EarlyPlot_Operate Project_EarlyPlot_Operate = new DataAccess.Operate.DA_Project_EarlyPlot_Operate();
                DataAccess.Operate.DA_Project_EarlyPlot_Inherit Project_EarlyPlot_Inherit = new DataAccess.Operate.DA_Project_EarlyPlot_Inherit();

                if (ViewState["ProjectID"] != null)
                {
                    Project_EarlyPlot.Project_EarlyPlot_MainID = new Guid(ViewState["ProjectID"].ToString());
                    Project_EarlyPlot_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_EarlyPlot_Operate.Insert(Project_EarlyPlot);
                    

                }
                else
                {
                    Project_EarlyPlot_Operate.Insert(Project_EarlyPlot);
                }
            }
            #endregion

            #region 销售代理（独立）部分
            if (this.chklAgencyType.Items[1].Selected)
            {

                Guid gSalseId = Guid.NewGuid();
                DataEntity.T_Project_SalseAgency Project_SalseAgency = new DataEntity.T_Project_SalseAgency();
                DataEntity.T_Project_SalseAgency_Exchange Project_SalseAgency_Exchange = new DataEntity.T_Project_SalseAgency_Exchange();
                DataAccess.Operate.DA_Project_SalseAgency_Operate Project_SalseAgency_Operate = new DataAccess.Operate.DA_Project_SalseAgency_Operate();
                DataAccess.Operate.DA_Project_SalseAgency_Inherit Project_SalseAgency_Inherit = new DataAccess.Operate.DA_Project_SalseAgency_Inherit();
                DataAccess.Operate.DA_Project_SalseAgency_Exchange_Operate Project_SalseAgency_Exchange_Operate = new DataAccess.Operate.DA_Project_SalseAgency_Exchange_Operate();
                DataAccess.Operate.DA_Project_SalseAgency_Exchange_Inherit Project_SalseAgency_Exchange_Inherit = new DataAccess.Operate.DA_Project_SalseAgency_Exchange_Inherit();
                Project_SalseAgency.Project_SalseAgency_ID = gSalseId;
                Project_SalseAgency.Project_SalseAgency_MainID = gProjectID;
                Project_SalseAgency.Project_SalseAgency_TypeID = Convert.ToInt32(radlSalseAgency.SelectedValue);
                Project_SalseAgency.Project_SalseAgency_FirstA1 = this.radlXsdl.SelectedValue;
                Project_SalseAgency.Project_SalseAgency_FirstA2 = this.hfldXsdlA2.Value;
                Project_SalseAgency.Project_SalseAgency_FirstA3 = this.hfldXsdlA3.Value;
                Project_SalseAgency.Project_SalseAgency_FirstB1 = ddlXsdl.SelectedValue;
                Project_SalseAgency.Project_SalseAgency_FirstB2 = this.hfldXsdlB2.Value;
                Project_SalseAgency_Exchange.Project_SalseAgency_Exchange_MainID = gProjectID;
                if (ViewState["ProjectID"] != null)
                {
                    Project_SalseAgency.Project_SalseAgency_MainID = new Guid(ViewState["ProjectID"].ToString());
                    Project_SalseAgency_Exchange.Project_SalseAgency_Exchange_MainID = new Guid(ViewState["ProjectID"].ToString());
                    Project_SalseAgency_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_SalseAgency_Exchange_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_SalseAgency_Operate.Insert(Project_SalseAgency);
                }
                else
                {
                    Project_SalseAgency_Operate.Insert(Project_SalseAgency);
                }

                if (this.hfldSalseAgency.Value != "")
                {

                    Project_SalseAgency_Exchange.Project_SalseAgency_Exchange_SalseAgencyMainID = gSalseId;
                    string[] arraySalseAgency = this.hfldSalseAgency.Value.Substring(0, this.hfldSalseAgency.Value.Length - 1).Split('|');
                    for (int i = 0; i < arraySalseAgency.Length; i++)
                    {
                        string[] objItem = arraySalseAgency[i].Split(',');
                        Project_SalseAgency_Exchange.Project_SalseAgency_Exchange_FirstA1 = objItem[0];
                        Project_SalseAgency_Exchange.Project_SalseAgency_Exchange_FirstA2 = objItem[1];
                        Project_SalseAgency_Exchange_Operate.Insert(Project_SalseAgency_Exchange);
                    }
                }
            }
            #endregion

            #region 招租部分
            if (this.chklAgencyType.Items[2].Selected == true)
            {
                
                DataAccess.Operate.DA_Project_Lease1_Operate Project_Lease1_Operate = new DataAccess.Operate.DA_Project_Lease1_Operate();
                DataAccess.Operate.DA_Project_Lease1_Inherit Project_Lease1_Inherit = new DataAccess.Operate.DA_Project_Lease1_Inherit();
                DataAccess.Operate.DA_Project_Lease_Exchange_Operate Project_Lease_Exchange_Operate = new DataAccess.Operate.DA_Project_Lease_Exchange_Operate();
                DataAccess.Operate.DA_Project_Lease_Exchange_Inherit Project_Lease_Exchange_Inherit = new DataAccess.Operate.DA_Project_Lease_Exchange_Inherit();
                DataEntity.T_Project_Lease Project_Lease = new DataEntity.T_Project_Lease();
                DataEntity.T_Project_Lease_Exchange Project_Lease_Exchange = new DataEntity.T_Project_Lease_Exchange();
                Guid gLeaseID = Guid.NewGuid();
                Project_Lease.Project_Lease_ID = gLeaseID;
                Project_Lease.Project_Lease_MainID = gProjectID;
                Project_Lease.Project_Lease_TypeID = Convert.ToInt32(this.radlLease.SelectedValue);
                Project_Lease.Project_Lease_FirstA1 = this.radlZz.SelectedValue;
                Project_Lease.Project_Lease_FirstA2 = this.hfldZzA2.Value;
                Project_Lease.Project_Lease_FirstA3 = this.hfldZzA3.Value;
                Project_Lease.Project_Lease_FirstB1 = this.ddlZz.SelectedValue;
                Project_Lease.Project_Lease_FirstB2 = this.hfldZzB2.Value;
                Project_Lease_Exchange.Project_Lease_Exchange_MainID = gProjectID;
                if (ViewState["ProjectID"] != null)
                {
                    Project_Lease.Project_Lease_MainID = new Guid(ViewState["ProjectID"].ToString());
                    Project_Lease_Exchange.Project_Lease_Exchange_MainID = new Guid(ViewState["ProjectID"].ToString());
                    Project_Lease1_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_Lease_Exchange_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_Lease1_Operate.Insert(Project_Lease);
                }
                else
                {
                    Project_Lease1_Operate.Insert(Project_Lease);
                }

                if (this.hfldLease.Value != "")
                {
                    string[] array = this.hfldLease.Value.Substring(0, hfldLease.Value.Length - 1).Split('|');
                    Project_Lease_Exchange.Project_Lease_Exchange_LeaseMainID = gLeaseID;
                    for (int i = 0; i < array.Length; i++)
                    {
                        string[] item = array[i].Split(',');
                        Project_Lease_Exchange.Project_Lease_Exchange_FirstA1 = item[0];
                        Project_Lease_Exchange.Project_Lease_Exchange_FirstA2 = item[1];
                        Project_Lease_Exchange_Operate.Insert(Project_Lease_Exchange);
                    }

                }
            }
            #endregion

            #region 联动部分
            if (ddlSignType.SelectedValue == "3" || this.chklAgencyType.Items[3].Selected)
            {
                string[] array = this.hfldUnionComm.Value.Substring(0, this.hfldUnionComm.Value.Length - 1).Split('|');
                DataAccess.Operate.DA_Project_UnionComm_Operate Project_UnionComm_Operate = new DataAccess.Operate.DA_Project_UnionComm_Operate();
                DataAccess.Operate.DA_Project_UnionDeveloper_Operate Project_UnionDeveloper_Operate = new DataAccess.Operate.DA_Project_UnionDeveloper_Operate();
                DataAccess.Operate.DA_Project_UnionComm_Inherit Project_UnionComm_Inherit = new DataAccess.Operate.DA_Project_UnionComm_Inherit();
                DataAccess.Operate.DA_Project_UnionDeveloper_Inherit Project_UnionDeveloper_Inherit = new DataAccess.Operate.DA_Project_UnionDeveloper_Inherit();
                DataEntity.T_Project_UnionComm Project_UnionComm = new DataEntity.T_Project_UnionComm();
                DataEntity.T_Project_UnionDeveloper Project_UnionDeveloper = new DataEntity.T_Project_UnionDeveloper();
                Project_UnionComm.Project_UnionComm_MainID = gProjectID;
                Project_UnionDeveloper.Project_UnionDeveloper_MainID = gProjectID;
                Project_UnionComm.Project_UnionComm_FirstA1 = Convert.ToInt32(radlUnionComm.SelectedValue);
                if (ViewState["ProjectID"] != null)
                {
                    Project_UnionComm_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_UnionDeveloper_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                    Project_UnionDeveloper.Project_UnionDeveloper_MainID = new Guid(ViewState["ProjectID"].ToString());
                    Project_UnionComm.Project_UnionComm_MainID = new Guid(ViewState["ProjectID"].ToString());
                }
                for (int i = 0; i < array.Length; i++)
                {
                    string[] entity = array[i].Split(',');
                    Project_UnionComm.Project_UnionComm_FirstA2 = entity[0];
                    Project_UnionComm.Project_UnionComm_FirstA3 = entity[1];
                    Project_UnionComm_Operate.Insert(Project_UnionComm);
                }

                array = this.hfldUnionDeveloper.Value.Substring(0, this.hfldUnionDeveloper.Value.Length - 1).Split('|');
                Project_UnionDeveloper.Project_UnionDeveloper_FirstA1 = Convert.ToInt32(radlUnionDeveloper.SelectedValue);
                for (int i = 0; i < array.Length; i++)
                {
                    string[] entity = array[i].Split(',');
                    Project_UnionDeveloper.Project_UnionDeveloper_FirstA2 = entity[0];
                    Project_UnionDeveloper.Project_UnionDeveloper_FirstA3 = entity[1];
                    Project_UnionDeveloper_Operate.Insert(Project_UnionDeveloper);
                }
            }
            #endregion

            //产品类型
            DataEntity.T_Project_ProductType Project_ProductType = new DataEntity.T_Project_ProductType();
            DataAccess.Operate.DA_Project_ProductType_Inherit Project_ProductType_Inherit = new DataAccess.Operate.DA_Project_ProductType_Inherit();
            DataAccess.Operate.DA_Project_ProductType_Operate Project_ProductType_Operate = new DataAccess.Operate.DA_Project_ProductType_Operate();
            Project_ProductType.Project_ProductType_MainID = gProjectID;
            if (ViewState["ProjectID"] != null)
            {
                Project_ProductType.Project_ProductType_MainID = new Guid(ViewState["ProjectID"].ToString());
                Project_ProductType_Inherit.DeleteByID(ViewState["ProjectID"].ToString());
            }
            for (int i = 0; i < chklProductType.Items.Count; i++)
            {
                if (chklProductType.Items[i].Selected)
                {
                        Project_ProductType.Project_ProductType_TypeID =Convert.ToInt32(chklProductType.Items[i].Value);
                        Project_ProductType_Operate.Insert(Project_ProductType);
                }
            }

            //当期报数点数
            DataEntity.T_Project_Point Project_Point = new DataEntity.T_Project_Point();
            DataAccess.Operate.DA_Project_Point_Operate Project_Point_Operate = new DataAccess.Operate.DA_Project_Point_Operate();
            Project_Point.Project_Point_MainID = gProjectID;
            if (ViewState["ProjectID"] != null)
            {
                DataAccess.Operate.DA_Project_Point_Inherit Project_Point_Inherit = new DataAccess.Operate.DA_Project_Point_Inherit();
                Project_Point_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                Project_Point.Project_Point_MainID = new Guid(ViewState["ProjectID"].ToString());
            }
            Project_Point.Project_Point_FirstA1 = txtPoint1.Text.Trim();
            Project_Point.Project_Point_SecondA1 = Convert.ToInt32(ddlPoint.SelectedValue.ToString());
            Project_Point.Project_Point_SecondA2 = hfdlPoint.Value;
            Project_Point.Project_Point_ThirdA1 = txtPoint31.Text.Trim();
            Project_Point.Project_Point_ThirdA2 = txtPoint32.Text.Trim();
            Project_Point_Operate.Insert(Project_Point);


            //结算条件
            DataEntity.T_Project_AccountCondition Project_AccountCondition = new DataEntity.T_Project_AccountCondition();
            DataAccess.Operate.DA_Project_AccountCondition_Operate Project_AccountCondition_Operate = new DataAccess.Operate.DA_Project_AccountCondition_Operate();
            Project_AccountCondition.Project_AccountCondition_MainID = gProjectID;
            if (ViewState["ProjectID"] != null)
            {
                DataAccess.Operate.DA_Project_AccountCondition_Inherit Project_AccountCondition_Inherit = new DataAccess.Operate.DA_Project_AccountCondition_Inherit();
                Project_AccountCondition_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                Project_AccountCondition.Project_AccountCondition_MainID = new Guid(ViewState["ProjectID"].ToString());
            }
            for (int i = 0; i < chklAccountCondition.Items.Count; i++)
            {
                if (chklAccountCondition.Items[i].Selected)
                {
                    Project_AccountCondition.Project_AccountCondition_AccountConditionID = Convert.ToInt32(chklAccountCondition.Items[i].Value.ToString());
                    if (i == 5)
                    {
                        Project_AccountCondition.Project_AccountCondition_AccountCondition = this.hfldAccountCondition.Value;
                    }
                    Project_AccountCondition_Operate.Insert(Project_AccountCondition);
                }
            }

            //以买家付款进度为结算条件
            DataEntity.T_Project_BidderAccountCondition Project_BidderAccountCondition = new DataEntity.T_Project_BidderAccountCondition();
            DataAccess.Operate.DA_Project_BidderAccountCondition_Operate Project_BidderAccountCondition_Operate = new DataAccess.Operate.DA_Project_BidderAccountCondition_Operate();
            Project_BidderAccountCondition.Project_BidderAccountCondition_MainID = gProjectID;
            if (ViewState["ProjectID"] != null)
            {
                DataAccess.Operate.DA_Project_BidderAccountCondition_Inherit Project_BidderAccountCondition_Inherit = new DataAccess.Operate.DA_Project_BidderAccountCondition_Inherit();
                Project_BidderAccountCondition_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                Project_BidderAccountCondition.Project_BidderAccountCondition_MainID = new Guid(ViewState["ProjectID"].ToString());
            }
            for (int i = 0; i < chklBidderAccountCondition.Items.Count; i++)
            {
                if (chklBidderAccountCondition.Items[i].Selected)
                {
                    Project_BidderAccountCondition.Project_BidderAccountCondition_BidderAccountConditionID = Convert.ToInt32(chklBidderAccountCondition.Items[i].Value);
                    Project_BidderAccountCondition_Operate.Insert(Project_BidderAccountCondition);
                }
            }

            //收佣条件
            DataEntity.T_Project_Commission Project_Commission = new DataEntity.T_Project_Commission();
            DataAccess.Operate.DA_Project_Commission_Operate Project_Commission_Operate = new DataAccess.Operate.DA_Project_Commission_Operate();
            Project_Commission.Project_Commission_MainID = gProjectID;
            if (ViewState["ProjectID"] != null)
            {
                DataAccess.Operate.DA_Project_Commission_Inherit Project_Commission_Inherit = new DataAccess.Operate.DA_Project_Commission_Inherit();
                Project_Commission_Inherit.DeleteByMainID(ViewState["ProjectID"].ToString());
                Project_Commission.Project_Commission_MainID = new Guid(ViewState["ProjectID"].ToString());
            }
            if (this.hfldCommission.Value != "")
            {
               
                string[] item = this.hfldCommission.Value.Substring(0, this.hfldCommission.Value.Length - 1).Split('|');
                for (int i = 0; i < item.Length; i++)
                {
                    string[] entity = item[i].Split(',');

                    Project_Commission.Project_Encourage_FirstA1 = entity[0];
                    Project_Commission.Project_Encourage_FirstA2 = entity[1];
                    Project_Commission.Project_Encourage_FirstA3 =Convert.ToInt32(entity[2]);
                    Project_Commission_Operate.Insert(Project_Commission);
                }
            }


            
            if (ViewState["ProjectID"] !=null)
            {
                string sTemp = "项目编号:" + Project.Project_NO.ToString() + "-新增成功!";
                this.Page.ClientScript.RegisterStartupScript(typeof(Page), "", "<script>alert('" + sTemp + "');window.close();</script>");
                //提醒营销[副]总监审批
                SendMessage("5", ViewState["ProjectID"].ToString());
              
            }
            

        }
        #endregion

        #region 修改时数据绑定
        private void Update_Data_Bind(string sProjectID)
        {
            DataSet ds = new DataSet();
            DataEntity.T_Project Project = new DataEntity.T_Project();
    
            DataEntity.T_Project_AgencyType Project_AgencyType = new DataEntity.T_Project_AgencyType();
            DataAccess.Operate.DA_Project_Operate Project_Operate = new DataAccess.Operate.DA_Project_Operate();
            DataAccess.Operate.DA_Project_AgencyType_Operate Project_AgencyType_Operate = new DataAccess.Operate.DA_Project_AgencyType_Operate();
            DataAccess.Operate.DA_Project_AgencyType_Inherit Project_AgencyType_Inherit = new DataAccess.Operate.DA_Project_AgencyType_Inherit();
            DataAccess.Operate.DA_Project_City_Inherit Project_City_Inherit = new DataAccess.Operate.DA_Project_City_Inherit();
            DataAccess.Operate.DA_Project_District_Inherit Project_District_Inherit = new DataAccess.Operate.DA_Project_District_Inherit();
            DataAccess.Operate.DA_Project_DistrictType_Inherit Project_DistrictType_Inherit = new DataAccess.Operate.DA_Project_DistrictType_Inherit();

            Project = (DataEntity.T_Project)Project_Operate.SelectOne(sProjectID);
            if (Project.Project_Audit > 1)
            {
                this.btnSubmit.Enabled = false;
                this.btnDelete.Enabled = false;
            }
            if (Project.Project_Audit == 2)
                this.btnAudit.Text = "营销[副]总监审核";
            if (Project.Project_Audit == 3)
                this.btnAudit.Text = "部门负责人审核";
            if (Project.Project_Audit == 4)
                this.btnAudit.Text = "系统管理员审核";
            if (Project.Project_Audit == 5)
            {
                this.btnAudit.Text = "审核已完成";
                this.btnAudit.Enabled = false;
            }

            if (!CommonFunction.isInPrev("Project_Deal_0005") && this.btnAudit.Text == "营销[副]总监审核")
            {
                this.btnAudit.Enabled = false;  //营销副总监
            }
            if (!CommonFunction.isInPrev("Project_Deal_0006") && this.btnAudit.Text == "部门负责人审核")
            {
                this.btnAudit.Enabled = false; //部门负责人
            }
            if (!CommonFunction.isInPrev("Project_Deal_0007") && this.btnAudit.Text == "系统管理员审核")
            {
                this.btnAudit.Enabled = false; //系统管理员
            }
          
            if (!Project.Project_ID.IsNull)
            {
                this.txtProjectName.Text = Project.Project_Name.IsNull ? "" : Project.Project_Name.ToString();
                this.txtDeveloper.Text = Project.Project_Developer.IsNull ? "" : Project.Project_Developer.ToString();
                this.txtSignDate.Text = Project.Project_SignDate.IsNull ? "" : Project.Project_SignDate.Value.ToString("yyyy-MM-dd");
                this.txtManager.Text = Project.Project_Manager.ToString();
                this.hfldManager.Value = Project.Project_ManagerCode.ToString();
                this.txtMarketing1.Text = Project.Project_Directer.ToString();
                this.hfldMarketing1.Value = Project.Project_DirecterCode.ToString();
                this.txtMarketing2.Text = Project.Project_Directer1.ToString();
                this.hfldMarketing2.Value = Project.Project_Directer1Code.ToString();
                this.txtBusiness.Text = Project.Project_Business.ToString();
                this.hfldBusiness.Value = Project.Project_BusinessCode.ToString();
                this.txtDepartmentHead.Text = Project.Project_DepartmentHead.ToString();
                this.hfldDepartmentHead.Value = Project.Project_DepartmentHeadCode.ToString();

                DataAccess.Operate.DA_Project_Hr_Inherit Project_Hr_Inherit = new DataAccess.Operate.DA_Project_Hr_Inherit();
                ds = Project_Hr_Inherit.GetFindAllByMainID(sProjectID);
                lstHr.DataSource = ds.Tables[0];
                lstHr.DataTextField = "Project_Hr_KDName";
                lstHr.DataValueField = "Project_Hr_KDNameID";
                lstHr.DataBind();

                this.ddlSignType.SelectedValue = Project.Project_SignTypeID.IsNull ? "" : Project.Project_SignTypeID.ToString();
                this.ddlDeveloperProvince.Text = Project.Project_DeveloperProvinceID.IsNull ? "" : Project.Project_DeveloperProvinceID.ToString();
                this.ddlDeveloperCity.Text = Project.Project_DeveloperCityID.IsNull ? "" : Project.Project_DeveloperCityID.ToString();
                this.ddlDeveloperDistrict.Text = Project.Project_DeveloperDistrictID.IsNull ? "" : Project.Project_DeveloperDistrictID.ToString();
                this.txtDeveloperAddress.Text = Project.Project_DeveloperAddress.IsNull ? "" : Project.Project_DeveloperAddress.ToString();
                this.ddlDistrictType.Text = Project.Project_DeveloperDistrictPropertyID.IsNull ? "" : Project.Project_DeveloperDistrictPropertyID.ToString();
                this.ddlDepartment.Text = Project.Project_DepartmentID.IsNull ? "" : Project.Project_DepartmentID.ToString();
                this.ddlProjectState.Text = Project.Project_PresentID.IsNull ? "" : Project.Project_PresentID.ToString();
                this.txtDateStart.Text = Project.Project_AgencyDateBegin.IsNull ? "" : Project.Project_AgencyDateBegin.Value.ToString("yyyy-MM-dd");
                this.txtDateEnd.Text = Project.Project_AgencyDateEnd.IsNull ? "" : Project.Project_AgencyDateEnd.Value.ToString("yyyy-MM-dd");
                this.txtProject_AvailableArea.Text = Project.Project_AvailableArea.ToString();
                this.txtProject_AvailableVolume.Text = Project.Project_AvailableVolume.ToString();
                //转介盘源转介费
                this.radlReferral.SelectedValue = Project.Project_Referral_ID.ToString();
                if (this.radlReferral.SelectedValue == "1")
                    this.radlReferral.Items[0].Text = "一次性支付" + Project.Project_Referral_FirstA1.ToString() + "元";
                else if (this.radlReferral.SelectedValue == "2")
                    this.radlReferral.Items[1].Text = "按中原实收佣金" + Project.Project_Referral_FirstA1.ToString() + "%计提（含税）";
                else if (this.radlReferral.SelectedValue == "3")
                    this.radlReferral.Items[2].Text = "按中原成交金额" + Project.Project_Referral_FirstA1.ToString() + "%计提（含税）";

                //对外分佣
                this.radlOutComm.SelectedValue = Project.Project_OutComm_ID.ToString();
                if (this.radlOutComm.SelectedValue == "1")
                    this.radlOutComm.Items[0].Text = "一次性支付" + Project.Project_OutComm_FirstA1.ToString() + "元";
                else if (this.radlOutComm.SelectedValue == "2")
                    this.radlOutComm.Items[1].Text = "按中原实收佣金" + Project.Project_OutComm_FirstA1.ToString() + "%计提（含税）";
                else if (this.radlOutComm.SelectedValue == "3")
                    this.radlOutComm.Items[2].Text = "按中原成交金额" + Project.Project_OutComm_FirstA1.ToString() + "%计提（含税）";

                //结算周期
                radlAccountCycle.SelectedValue = Project.Project_AccountCycle.ToString();
                if (radlAccountCycle.SelectedValue == "3")
                    radlAccountCycle.Items[2].Text = "每月" + Project.Project_AccountCycle_FirstA1.ToString() + "日";

                //完成销售目标作为结算条件
                radlSalseAccountCondition.SelectedValue = Project.Project_AccountCondition.ToString();
                if (radlSalseAccountCondition.SelectedValue == "1")
                    radlSalseAccountCondition.Items[0].Text = "达到首个销售目标(" + Project.Project_AccountCondition_FirstA1.ToString() + ")";
                else if (radlSalseAccountCondition.SelectedValue == "2")
                    radlSalseAccountCondition.Items[1].Text = "达到第二个销售目标(" + Project.Project_AccountCondition_FirstA1.ToString() + ")";
                else if (radlSalseAccountCondition.SelectedValue == "3")
                    radlSalseAccountCondition.Items[2].Text = "达到第三个销售目标(" + Project.Project_AccountCondition_FirstA1.ToString() + ")";
                else if (radlSalseAccountCondition.SelectedValue == "4")
                    radlSalseAccountCondition.Items[3].Text = "达到第四个销售目标(" + Project.Project_AccountCondition_FirstA1.ToString() + ")";
                else if (radlSalseAccountCondition.SelectedValue == "5")
                    radlSalseAccountCondition.Items[4].Text = "达到第五个销售目标(" + Project.Project_AccountCondition_FirstA1.ToString() + ")";
                else if (radlSalseAccountCondition.SelectedValue == "6")
                    radlSalseAccountCondition.Items[5].Text = "完成年度销售目标(" + Project.Project_AccountCondition_FirstA1.ToString() + ")";

                
                
      

                ds = Project_City_Inherit.FindLibrary(Convert.ToInt32(Project.Project_DeveloperProvinceID.IsNull ? "0" : Project.Project_DeveloperProvinceID.ToString()));
                Common.Common_Function.DropDownListBind(ddlDeveloperCity, ds.Tables[0], "City_ID", "City_Name", "", "--城市--");
                this.ddlDeveloperCity.SelectedValue = Project.Project_DeveloperCityID.IsNull ? "0" : Project.Project_DeveloperCityID.ToString();

                ds = Project_District_Inherit.FindLibrary(Convert.ToInt32(Project.Project_DeveloperCityID.IsNull ? "0" : Project.Project_DeveloperCityID.ToString()));
                Common.Common_Function.DropDownListBind(ddlDeveloperDistrict, ds.Tables[0], "District_ID", "District_Name", "", "--区--");
                this.ddlDeveloperDistrict.SelectedValue = Project.Project_DeveloperDistrictID.IsNull ? "0" : Project.Project_DeveloperDistrictID.ToString();

                ds = Project_DistrictType_Inherit.FindLibraryByID(Convert.ToInt32(Project.Project_DeveloperDistrictPropertyID.IsNull ? "0" : Project.Project_DeveloperDistrictPropertyID.ToString()));
                Common.Common_Function.DropDownListBind(ddlDistrictType, ds.Tables[0], "Project_DistrictType_ID", "Project_DistrictType_Name", "", "");
                this.ddlDistrictType.SelectedValue = Project.Project_DeveloperDistrictPropertyID.IsNull ? "0" : Project.Project_DeveloperDistrictPropertyID.ToString();



                #region 产品类型
                DataAccess.Operate.DA_Project_ProductType_Inherit Project_ProductType_Inherit = new DataAccess.Operate.DA_Project_ProductType_Inherit();
                ds = Project_ProductType_Inherit.FindProjectAllByID(sProjectID);
                if (ds.Tables[0] != null)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < chklProductType.Items.Count; j++)
                        {
                            if (chklProductType.Items[j].Value == ds.Tables[0].Rows[i]["Project_ProductType_TypeID"].ToString())
                            {
                                chklProductType.Items[j].Selected = true;
                            }
                        }
                    }
                }
                #endregion

                #region 代理类型

                ds = Project_AgencyType_Inherit.FindProjectAllByID(sProjectID);
                if (ds.Tables[0] != null)
                {

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < this.chklAgencyType.Items.Count; j++)
                        {
                            if (chklAgencyType.Items[j].Value == ds.Tables[0].Rows[i][0].ToString())
                            {
                                chklAgencyType.Items[j].Selected = true;
                            }
                        }
                      
                    }
                }
                #endregion

                #region 修改时显示-额外奖励部分
                DataAccess.Operate.DA_Project_Encourage_Inherit Project_Encourage_Inherit = new DataAccess.Operate.DA_Project_Encourage_Inherit();
                ds = Project_Encourage_Inherit.GetAllByMainID(sProjectID);
                string sTitle = "";
                string sHtml = "";
                string sType = "";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    sType = ds.Tables[0].Rows[0]["Project_Encourage_FirstA1"].ToString();
                    if (sType == "1")
                        sTitle = "成交金额";
                    else if (sType == "2")
                        sTitle = "套数";
                    else if (sType == "3")
                        sTitle = "面积";
                    sHtml = "var div=document.createElement('div');div.innerHTML='" + (i + 1) + "." + sTitle + "<input type=\"text\" class=\"edline\" name=\"inputEncourage1\" value=\"" + ds.Tables[0].Rows[i]["Project_Encourage_FirstA2"] + "\"  />以上，按<input type=\"text\" name=\"inputEncourage2\" class=\"edline\" value=\"" + ds.Tables[0].Rows[i]["Project_Encourage_FirstA3"] + "\" />%计提<input type=\"button\" value=\"删除\" onclick=\"DelArea(&quot;EncourageArea&quot;,this.parentNode)\">';document.getElementById('EncourageArea').appendChild(div);n=" + (i + 2) + "";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript" + i, "<script>" + sHtml + "</script> ");
                }
                this.radlEncourage.SelectedValue = sType==""?null:sType;
                #endregion

                if (this.chklAgencyType.Items[0].Selected)
                {
                    #region 修改时显示-前期策划部分
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "EarlyPlotscript", "<script>document.getElementById('lk2').style.display='inline-block';</script> ");
                    DataAccess.Operate.DA_Project_EarlyPlot_Inherit Project_EarlyPlot_Inherit = new DataAccess.Operate.DA_Project_EarlyPlot_Inherit();
                    DataEntity.T_Project_EarlyPlot Project_EarlyPlot = (DataEntity.T_Project_EarlyPlot)Project_EarlyPlot_Inherit.SelectOneByMainID(sProjectID);
                    txtQqchA1.Text = Project_EarlyPlot.Project_EarlyPlot_FirstA1.ToString();
                    ddlQqchA.SelectedValue = Project_EarlyPlot.Project_EarlyPlot_FirstA2.ToString();
                    txtQqchA2.Text = Project_EarlyPlot.Project_EarlyPlot_FirstA3.ToString();
                    txtQqchB1.Text = Project_EarlyPlot.Project_EarlyPlot_FirstB1.ToString();
                    ddlQqchB.SelectedValue = Project_EarlyPlot.Project_EarlyPlot_FirstB2.ToString();
                    txtQqchB2.Text = Project_EarlyPlot.Project_EarlyPlot_FirstB3.ToString();
                    txtQqchC1.Text = Project_EarlyPlot.Project_EarlyPlot_FirstC1.ToString();
                    ddlQqchC.SelectedValue = Project_EarlyPlot.Project_EarlyPlot_FirstC2.ToString();
                    txtQqchC2.Text = Project_EarlyPlot.Project_EarlyPlot_FirstC3.ToString();
                    txtQqchD1.Text = Project_EarlyPlot.Project_EarlyPlot_FirstD1.ToString();
                    ddlQqchD.SelectedValue = Project_EarlyPlot.Project_EarlyPlot_FirstD2.ToString();
                    txtQqchD2.Text = Project_EarlyPlot.Project_EarlyPlot_FirstD3.ToString();
                    txtQqchE1.Text = Project_EarlyPlot.Project_EarlyPlot_FirstE1.ToString();
                    ddlQqchE.SelectedValue = Project_EarlyPlot.Project_EarlyPlot_FirstE2.ToString();
                    txtQqchE2.Text = Project_EarlyPlot.Project_EarlyPlot_FirstE3.ToString();
                    this.txtProject_EarlyPlot_Fees.Text = Project_EarlyPlot.Project_EarlyPlot_Fees.ToString();
                    txtQqch21.Value = Project_EarlyPlot.Project_EarlyPlot_Second1.ToString();
                    if (txtQqch21.Value != "")
                    {
                        ddlQqch2.Items[0].Text = "每月" + txtQqch21.Value + "日";
                    }
                    ddlQqch2.SelectedValue = Project_EarlyPlot.Project_EarlyPlot_Second2.ToString();
                    txtQqch22.Text = Project_EarlyPlot.Project_EarlyPlot_Second3.ToString();
                    #endregion
                }
                if (this.chklAgencyType.Items[1].Selected)
                {
                    #region 修改时显示-销售代理部分
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "SalseAgencyscript", "<script>document.getElementById('lk3').style.display='inline-block';</script> ");
                    DataAccess.Operate.DA_Project_SalseAgency_Inherit Project_SalseAgency_Inherit = new DataAccess.Operate.DA_Project_SalseAgency_Inherit();
                    DataEntity.T_Project_SalseAgency Project_SalseAgency = new DataEntity.T_Project_SalseAgency();
                    Project_SalseAgency = (DataEntity.T_Project_SalseAgency)Project_SalseAgency_Inherit.SelectOneByMainID(sProjectID);
                    radlSalseAgency.SelectedValue = Project_SalseAgency.Project_SalseAgency_TypeID.ToString();

                    this.radlXsdl.SelectedValue = Project_SalseAgency.Project_SalseAgency_FirstA1.ToString();
                    this.hfldXsdlA2.Value = Project_SalseAgency.Project_SalseAgency_FirstA2.ToString();
                    this.hfldXsdlA3.Value = Project_SalseAgency.Project_SalseAgency_FirstA3.ToString();
                    if (radlXsdl.SelectedValue == "1")
                    {
                        radlXsdl.Items[0].Text = hfldXsdlA2.Value + "套以内";
                    }
                    else if (radlXsdl.SelectedValue == "2")
                    {
                        radlXsdl.Items[1].Text = "可售货量" + hfldXsdlA2.Value + "套的" + hfldXsdlA3.Value + "以内";
                    }
                    ddlXsdl.SelectedValue = Project_SalseAgency.Project_SalseAgency_FirstB1.ToString();
                    this.hfldXsdlB2.Value = Project_SalseAgency.Project_SalseAgency_FirstB2.ToString();
                    if (ddlXsdl.SelectedValue == "1")
                    {
                        ddlXsdl.Items[0].Text = "按成交金额的" + hfldXsdlB2.Value + "%计提";
                    }
                    else if (ddlXsdl.SelectedValue == "2")
                        ddlXsdl.Items[1].Text = "每套按" + hfldXsdlB2.Value + "元收取手续费";

                    DataAccess.Operate.DA_Project_SalseAgency_Exchange_Inherit Project_SalseAgency_Exchange_Inherit = new DataAccess.Operate.DA_Project_SalseAgency_Exchange_Inherit();
                    ds = Project_SalseAgency_Exchange_Inherit.GetAllBySalseAgencyID(sProjectID);
                    sHtml = "";
                    sTitle = "";
                    if (this.radlSalseAgency.SelectedItem.Text == "按面积幅度")
                        sTitle = "面积";
                    else if (this.radlSalseAgency.SelectedItem.Text == "按套数幅度")
                        sTitle = "套数";
                    else if (this.radlSalseAgency.SelectedItem.Text == "按成交金额幅度")
                        sTitle = "成交金额";
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //this.hfldSalseAgency.Value += ds.Tables[0].Rows[i]["Project_SalseAgency_Exchange_FirstA1"] + "," + ds.Tables[0].Rows[i]["Project_SalseAgency_Exchange_FirstA2"]+"|";
                        sHtml = "var div=document.createElement('div');div.innerHTML='" + (i + 1) + "." + sTitle + "<input type=\"text\" class=\"edline\" name=\"inputSalseAgency1\" value=\"" + ds.Tables[0].Rows[i]["Project_SalseAgency_Exchange_FirstA1"] + "\"  />以上，按<input type=\"text\" name=\"inputSalseAgency2\" class=\"edline\" value=\"" + ds.Tables[0].Rows[i]["Project_SalseAgency_Exchange_FirstA2"] + "\" />%计提<input type=\"button\" value=\"删除\" onclick=\"DelArea(&quot;SalseAgencyArea&quot;,this.parentNode)\">';document.getElementById('SalseAgencyArea').appendChild(div);s=" + (i + 2) + "";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "SalseAgencyscript" + i, "<script>" + sHtml + "</script> ");
                    }
                    #endregion
                }
                if (this.chklAgencyType.Items[2].Selected)
                {
                    #region 修改时显示-招租部分
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "Leasescript", "<script>document.getElementById('lk4').style.display='inline-block';</script> ");
                    DataAccess.Operate.DA_Project_Lease1_Inherit Project_Lease1_Inherit = new DataAccess.Operate.DA_Project_Lease1_Inherit();
                    DataEntity.T_Project_Lease Project_Lease = (DataEntity.T_Project_Lease)Project_Lease1_Inherit.SelectOneByMainID(sProjectID);
                    this.radlLease.SelectedValue = Project_Lease.Project_Lease_TypeID.ToString();
                    this.radlZz.SelectedValue = Project_Lease.Project_Lease_FirstA1.ToString();
                    this.hfldZzA2.Value = Project_Lease.Project_Lease_FirstA2.ToString();
                    this.hfldZzA3.Value = Project_Lease.Project_Lease_FirstA3.ToString();
                    if (this.radlZz.SelectedValue == "1")
                        this.radlZz.Items[0].Text = this.hfldZzA2.Value + "套以内";
                    else if (this.radlZz.SelectedValue == "2")
                        this.radlZz.Items[1].Text = "可售货量" + this.hfldZzA2.Value + "套的" + hfldZzA3.Value + "%以内";
                    this.ddlZz.SelectedValue = Project_Lease.Project_Lease_FirstB1.ToString();
                    this.hfldZzB2.Value = Project_Lease.Project_Lease_FirstB2.ToString();
                    if (this.ddlZz.SelectedValue == "1")
                        this.ddlZz.Items[0].Text = "按成交金额的" + hfldZzB2.Value + "%计提";
                    else if (this.ddlZz.SelectedValue == "2")
                        this.ddlZz.Items[1].Text = "每套按" + hfldZzB2.Value + "元收取手续费";

                    DataAccess.Operate.DA_Project_Lease_Exchange_Inherit Project_Lease_Exchange_Inherit = new DataAccess.Operate.DA_Project_Lease_Exchange_Inherit();
                    ds = Project_Lease_Exchange_Inherit.GetAllByID(sProjectID);
                    sHtml = "";
                    sTitle = "";
                    if (this.radlLease.SelectedValue == "1")
                        sTitle = "招赁套数";
                    else if (this.radlLease.SelectedValue == "2")
                        sTitle = "面积";
                    else if (this.radlLease.SelectedValue == "3")
                        sTitle = "货量";
                    else if (this.radlLease.SelectedValue == "4")
                        sTitle = "月均租金";

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        sHtml = "var div=document.createElement('div');div.innerHTML='" + (i + 1) + "." + sTitle + "<input type=\"text\" class=\"edline\" name=\"inputLease1\" value=\"" + ds.Tables[0].Rows[i]["Project_Lease_Exchange_FirstA1"] + "\"  />以上，按<input type=\"text\" name=\"inputLease2\" class=\"edline\" value=\"" + ds.Tables[0].Rows[i]["Project_Lease_Exchange_FirstA2"] + "\" />%计提<input type=\"button\" value=\"删除\" onclick=\"DelArea(&quot;LeaseArea&quot;,this.parentNode)\">';document.getElementById('LeaseArea').appendChild(div);l=" + (i + 2) + "";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "Leasescript" + i, "<script>" + sHtml + "</script> ");
                    }
                    #endregion
                }
                if (this.chklAgencyType.Items[3].Selected || this.ddlSignType.SelectedValue == "3")
                {
                    #region 修改时显示-联动部分
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "UnionCommscript", "<script>document.getElementById('lk5').style.display='inline-block';</script> ");
                    DataAccess.Operate.DA_Project_UnionComm_Inherit Project_UnionComm_Inherit = new DataAccess.Operate.DA_Project_UnionComm_Inherit();
                    ds = Project_UnionComm_Inherit.GetAllByMainID(sProjectID);
                    sHtml = "";
                    sTitle = "";
                    sType = "";
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        sType = ds.Tables[0].Rows[0]["Project_UnionComm_FirstA1"].ToString();
                        if (sType == "1")
                            sTitle = "成交金额";
                        else if (sType == "2")
                            sTitle = "套数";
                        else if (sType == "3")
                            sTitle = "面积";
                        sHtml = "var div=document.createElement('div');div.innerHTML='" + (i + 1) + "." + sTitle + "<input type=\"text\" class=\"edline\" name=\"inputUnionComm1\" value=\"" + ds.Tables[0].Rows[i]["Project_UnionComm_FirstA2"] + "\"  />以上，按<input type=\"text\" name=\"inputUnionComm2\" class=\"edline\" value=\"" + ds.Tables[0].Rows[i]["Project_UnionComm_FirstA3"] + "\" />%计提<input type=\"button\" value=\"删除\" onclick=\"DelArea(&quot;UnionCommArea&quot;,this.parentNode)\">';document.getElementById('UnionCommArea').appendChild(div);u=" + (i + 2) + "";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "UnionCommscript" + i, "<script>" + sHtml + "</script> ");
                    }
                    this.radlUnionComm.SelectedValue = sType;

                    DataAccess.Operate.DA_Project_UnionDeveloper_Inherit Project_UnionDeveloper_Inherit = new DataAccess.Operate.DA_Project_UnionDeveloper_Inherit();

                    ds = Project_UnionDeveloper_Inherit.GetAllByMainID(sProjectID);
                    sHtml = "";
                    sTitle = "";
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        sType = ds.Tables[0].Rows[0]["Project_UnionDeveloper_FirstA1"].ToString();
                        if (sType == "1")
                            sTitle = "成交金额";
                        else if (sType == "2")
                            sTitle = "套数";
                        else if (sType == "3")
                            sTitle = "面积";
                        sHtml = "var div=document.createElement('div');div.innerHTML='" + (i + 1) + "." + sTitle + "<input type=\"text\" class=\"edline\" name=\"inputUnionDeveloper1\" value=\"" + ds.Tables[0].Rows[i]["Project_UnionDeveloper_FirstA2"] + "\"  />以上，按<input type=\"text\" name=\"inputUnionDeveloper2\" class=\"edline\" value=\"" + ds.Tables[0].Rows[i]["Project_UnionDeveloper_FirstA3"] + "\" />%计提<input type=\"button\" value=\"删除\" onclick=\"DelArea(&quot;UnionDeveloperArea&quot;,this.parentNode)\">';document.getElementById('UnionDeveloperArea').appendChild(div);d=" + (i + 2) + "";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "UnionDeveloperscript" + i, "<script>" + sHtml + "</script> ");
                    }
                    this.radlUnionDeveloper.SelectedValue = sType;
                    #endregion
                }


                #region 当前报数部分
                DataAccess.Operate.DA_Project_Point_Inherit Project_Point_Inherit = new DataAccess.Operate.DA_Project_Point_Inherit();
                DataEntity.T_Project_Point Project_Point = Project_Point_Inherit.SelectOne(sProjectID);
                txtPoint1.Text = Project_Point.Project_Point_FirstA1.ToString();
                ddlPoint.SelectedValue = Project_Point.Project_Point_SecondA1.ToString();
                ddlPoint.Items[1].Text = "月均租金的" + Project_Point.Project_Point_SecondA2.ToString() + "倍计提";
                txtPoint31.Text = Project_Point.Project_Point_ThirdA1.ToString();
                txtPoint32.Text = Project_Point.Project_Point_ThirdA2.ToString();
                #endregion

                #region 结算条件部分

                DataAccess.Operate.DA_Project_AccountCondition_Inherit Project_AccountCondition_Inherit = new DataAccess.Operate.DA_Project_AccountCondition_Inherit();
                ds = Project_AccountCondition_Inherit.FindByMainID(sProjectID);
                for (int i = 0; i < chklAccountCondition.Items.Count; i++)
                {
                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                    {
                        if (i == 5)
                        {
                            if (ds.Tables[0].Rows[j]["Project_AccountCondition_AccountCondition"].ToString() != "")
                            {
                                chklAccountCondition.Items[i].Text = "每月" + ds.Tables[0].Rows[j]["Project_AccountCondition_AccountCondition"].ToString() + "日前";
                            }
                        }
                        if (chklAccountCondition.Items[i].Value == ds.Tables[0].Rows[j][2].ToString())
                        {
                            chklAccountCondition.Items[i].Selected = true;
                        }
                    }

                }
                #endregion

                #region 以买家付款进度作为结算条件部分
                DataAccess.Operate.DA_Project_BidderAccountCondition_Inherit BidderAccountCondition_Inherit = new DataAccess.Operate.DA_Project_BidderAccountCondition_Inherit();
                ds = BidderAccountCondition_Inherit.FindByMainID(sProjectID);
                for (int i = 0; i < chklBidderAccountCondition.Items.Count; i++)
                {
                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                    {
                        if (chklBidderAccountCondition.Items[i].Value == ds.Tables[0].Rows[j][2].ToString())
                        {
                            chklBidderAccountCondition.Items[i].Selected = true;
                        }
                    }
                }

                #endregion

                #region 收佣条件部分
                DataAccess.Operate.DA_Project_Commission_Inherit Project_Commission_Inherit = new DataAccess.Operate.DA_Project_Commission_Inherit();
                ds = Project_Commission_Inherit.FindByMainID(sProjectID);
                sHtml = "";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string FirstA30 = ds.Tables[0].Rows[i]["Project_Encourage_FirstA3"].ToString() == "0" ? "selected=\"selected\"" : "";
                    string FirstA31 = ds.Tables[0].Rows[i]["Project_Encourage_FirstA3"].ToString() == "1" ? "selected=\"selected\"" : "";

                    if (i == 0)
                    {
                        sHtml = "document.getElementById('Commission1').value='" + ds.Tables[0].Rows[0]["Project_Encourage_FirstA1"] + "';document.getElementById('Commission3').value='" + ds.Tables[0].Rows[0]["Project_Encourage_FirstA2"] + "';document.all.Commission2.value='" + ds.Tables[0].Rows[i]["Project_Encourage_FirstA3"].ToString() + "';";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "Commissionscript0", "<script>" + sHtml + "</script> ");
                    }
                    else
                    {
                        sHtml = "var div=document.createElement('div');div.innerHTML='以结算条件作为选项的<input name=\"Commission1\" value=\"" + ds.Tables[0].Rows[i]["Project_Encourage_FirstA1"] + "\" type=\"text\" style=\"width:40px;\"  /><select name=\"Commission2\"  ><option value=\"0\" " + FirstA30 + " >天</option><option value=\"1\" " + FirstA31 + " >工作天</option></select>内,支付<input name=\"Commission3\" value=\"" + ds.Tables[0].Rows[i]["Project_Encourage_FirstA2"] + "\" style=\"width:40px;\" type=\"text\" />%;<input id=\"Button2\" type=\"button\" value=\"删除\" onclick=\"DelArea(&quot;CommissionArea&quot;,this.parentNode)\" />';document.getElementById('CommissionArea').appendChild(div);";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "Commissionscript" + i, "<script>" + sHtml + "</script> ");
                    }
                }
                #endregion

            }


        }
        #endregion

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string ID = ViewState["ProjectID"].ToString();
            DataAccess.Operate.DA_Project_Operate Project_Operate = new DataAccess.Operate.DA_Project_Operate();
            if (Project_Operate.Delete(ID))
            {
                Response.Write("<script>alert('删除成功');window.close(); </script>");
                DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 1,new Guid(ViewState["ProjectID"].ToString()), 3);
            }
            else
            {
                Response.Write("<script>alert('删除失败');window.close(); </script>");
            }
        }

        protected void btnUpLoad_Click(object sender, EventArgs e)
        {
            DataAccess.Operate.DA_Report_Attach_Operate Report_Attach_Operate = new DataAccess.Operate.DA_Report_Attach_Operate();
            DataEntity.T_Report_Attach Report_Attach = new DataEntity.T_Report_Attach();
            string sFileName = "";
            string sFilePath = "";
            string sFileType = "";

            Guid gProjectID = new Guid(ViewState["ProjectID"].ToString());
            if (!Directory.Exists("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString()))
            {
                Directory.CreateDirectory("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString());
            }
            if (!Directory.Exists("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString() + "\\" + ViewState["ProjectID"].ToString()))
            {
                Directory.CreateDirectory("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString() + "\\" + ViewState["ProjectID"].ToString());
            }

            sFileType = CommonFunction.CheckFileType(this.txtFilePath.PostedFile.FileName);
            if (sFileType != "")
            {
                sFileName = ViewState["ProjectID"].ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + sFileType;
            }

            sFilePath = "/ReportManager/" + DateTime.Now.Year + "/" + ViewState["ProjectID"].ToString() + "/" + sFileName;
            try
            {
                Report_Attach.Project_Report_FileDesc = this.txtProjectDesc.Text.Trim();
                Report_Attach.Project_Report_FileName = sFileName;
                Report_Attach.Project_Report_FilePath = sFilePath;
                Report_Attach.Project_Report_ExchangeTypeID = 11;
                Report_Attach.Project_Report_FileID =Convert.ToInt32(this.ddlFileType.SelectedValue);
                Report_Attach.Project_Report_MainID = new Guid(ViewState["ProjectID"].ToString());
                Report_Attach_Operate.Insert(Report_Attach);
                this.txtFilePath.PostedFile.SaveAs("\\\\gzs-ecc02\\ReportManager\\" + DateTime.Now.Year.ToString() + "\\" + ViewState["ProjectID"].ToString() + "\\" + sFileName);
                DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 5, new Guid(ViewState["ProjectID"].ToString()), 4);
                BindGrid();
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                this.ddlFileType.SelectedValue = "";
                Update_Data_Bind(ViewState["ProjectID"].ToString());
            }
        }

        #region BindGrid
        private void BindGrid()
        {
            DataSet ds = new DataSet();
            DataAccess.Operate.DA_Report_Attach_Inherit Report_Attach_Inherit = new DataAccess.Operate.DA_Report_Attach_Inherit();

            dgList.DataBind();
            ds = Report_Attach_Inherit.GetAllByReportID(ViewState["ProjectID"].ToString());
            dgList.DataSource = ds;
            dgList.DataBind();

            this.HiddenField2.Value = "123"; //随便赋值，以便再次提交时前台验证通过
        }
        #endregion

        protected void dgList_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.Item.ItemIndex > -1)
                {
                    ImageButton imgbtnDelete = (ImageButton)e.Item.FindControl("imgbtnDelete");
                    imgbtnDelete.Attributes.Add("onclick", "return window.confirm(\"是否确定删除？\")");

                }
            }
        }

        protected void dgList_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            DataAccess.Operate.DA_Report_Attach_Operate Report_Attach_Operate = new DataAccess.Operate.DA_Report_Attach_Operate();
            if (e.CommandName.ToString() == "Delete")
            {
                try
                {
                    Report_Attach_Operate.Delete(new Guid(dgList.DataKeys[e.Item.ItemIndex].ToString()));
                    DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 5, new Guid(ViewState["ProjectID"].ToString()), 3);
                    this.BindGrid();
                }
                catch (System.Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
                finally
                {
                    Report_Attach_Operate = null;
                    Update_Data_Bind(ViewState["ProjectID"].ToString());
                }
            }
        }


        #region WebClient上传附件
        /// <summary>
        /// WebClient上传文件至服务器
        /// </summary>
        /// <param name="fileNamePath">文件名，全路径格式</param>
        /// <param name="uriString">服务器文件夹路径</param>
        public void UpLoadFile(string fileNamePath, string uriString)
        {
            /**/
            /// 创建WebClient实例 
            WebClient myWebClient = new WebClient();
            myWebClient.Credentials = CredentialCache.DefaultCredentials;
            // 要上传的文件 
            FileStream fs = new FileStream(fileNamePath, FileMode.Open, FileAccess.Read);
            // FileStream fs = OpenFile(); 
            BinaryReader r = new BinaryReader(fs);
            byte[] postArray = r.ReadBytes((int)fs.Length);
            Stream postStream = myWebClient.OpenWrite(uriString, " PUT ");
            try
            {

                // 使用UploadFile方法可以用下面的格式
                // myWebClient.UploadFile(uriString,"PUT",fileNamePath); 

                if (postStream.CanWrite)
                {
                    postStream.Write(postArray, 0, postArray.Length);
                    postStream.Close();
                    fs.Dispose();
                }
                else
                {
                    postStream.Close();
                    fs.Dispose();

                }
            }
            catch (Exception err)
            {
                postStream.Close();
                fs.Dispose();
                // Utility.LogWriter log = new Utility.LogWriter(); 
                throw err;
            }
            finally
            {
                postStream.Close();
                fs.Dispose();
            }
        }
        #endregion

        protected void btnAudit_Click(object sender, EventArgs e)
        {
            //用按钮的文字来判断审批进行到哪一步
            if (this.btnAudit.Text == "营销[副]总监审核")
            {
                DataAccess.Operate.DA_Project_Inherit Project_Inherit = new DataAccess.Operate.DA_Project_Inherit();
                if (Project_Inherit.AuditByID(ViewState["ProjectID"].ToString(), "3"))
                {
                   
                    DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 6,new Guid(ViewState["ProjectID"].ToString()), 5);
                    Response.Write("<script>alert('审核成功');window.close();</script>");
                    //提醒部分负责人审核
                    SendMessage("6", ViewState["ProjectID"].ToString());
                }
            }
            else if (this.btnAudit.Text == "部门负责人审核")
            {
            
                DataAccess.Operate.DA_Project_Inherit Project_Inherit = new DataAccess.Operate.DA_Project_Inherit();
                if (Project_Inherit.AuditByID(ViewState["ProjectID"].ToString(), "4"))
                {
                    
                    DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 6, new Guid(ViewState["ProjectID"].ToString()), 6);
                    Response.Write("<script>alert('审核成功');window.close();</script>");
                    //提醒系统管理员审核
                    SendMessage("7", ViewState["ProjectID"].ToString());
                }

            }
            else if (this.btnAudit.Text == "系统管理员审核")
            {
                DataAccess.Operate.DA_Project_Inherit Project_Inherit = new DataAccess.Operate.DA_Project_Inherit();
                if (Project_Inherit.AuditByID(ViewState["ProjectID"].ToString(), "5"))
                {
                    DataAccess.Multi.System_Multi.addLog(Session["EmployeeID"].ToString(), Session["EmployeeName"].ToString(), 6, new Guid(ViewState["ProjectID"].ToString()), 7);
                    Response.Write("<script>alert('审核成功');window.close();</script>");
                }
            }
          
        }

        public void SendMessage(string operate, string project)
        {

            string projectNo = "";
            DataAccess.Operate.DA_Project_Inherit Project_Inherit = new DataAccess.Operate.DA_Project_Inherit();
            string[] array = Project_Inherit.getCodeAndName(out projectNo,operate, project);
            string sTitle = "请注意，项目编号:" + projectNo + " 需要您的审批。";
            string sBody = "请注意，项目编号:" + projectNo + " 需要您的审批。<a href='http://gzs-ecc02'>点击此处</a>";
            // array[1] 姓名 ，array[0] 工号
            EcSalseManage.App_Code.CommonFunction.SendMessage(array[1], array[0], sTitle, sBody);

        }

        protected void btnAddHr_Click(object sender, EventArgs e)
        {
            if (txtUserInput.Text.Trim() == "")
                return;
            ListItem item = new ListItem(this.txtUserInput.Text, this.HiddenField1.Value);
            lstHr.Items.Add(item);
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            int index = lstHr.SelectedIndex;
            if (index > -1)
            {
                lstHr.Items.Remove(lstHr.Items[index]);
            }
        }


    }
}